﻿using BCCommon;
using BCDto.Common.ErrorMessage;
using BCDto.MySql.MaterialConfiguration;
using BCService.WebDomainService.MaterialConfigurationService;
using Microsoft.AspNetCore.Mvc;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;

namespace BCTMSRESTful.Controllers.Management.System.MaterialConfiguration
{
    /// <summary>
    /// 素材控制器
    /// </summary>
    [ApiExplorerSettings(GroupName = "Admin")]
    [Route("api/v1/sim/[controller]")]

    public class MaterialConfigurationController : ManagementBaseController
    {

        private readonly IMaterialConfigurationService materialConfigurationService;

        public MaterialConfigurationController(IMaterialConfigurationService materialConfigurationService)
        {
            this.materialConfigurationService = materialConfigurationService;
        }


        #region 获取素材信息列表（分页）
        /// <summary>
        /// 获取素材信息列表（分页）。
        /// </summary>
        /// <param name="materialName">素材名称</param>
        /// <param name="materialType">素材类型</param>
        /// <param name="remark">素材备注</param> 
        /// <param name="usageGroupCode">用途组编码</param> 
        /// <param name="start">开始时间</param>
        /// <param name="end">结束时间</param>
        /// <param name="ascending">是否升序</param>        
        /// <param name="index">当前页码</param>
        /// <param name="size">当前页大小</param>
        /// <response code="200">获取用戶信息列表</response>
        /// <response code="400">请求参数或输入的数据不正确。</response>
        /// <response code="500">服务器发生错误。</response>
        /// <response code="501">某些功能尚未实现。</response>
        /// <returns></returns>
        [HttpGet]
        [ProducesResponseType(typeof(PageableList<MaterialConfigurationDto>), 200)]
        [ProducesResponseType(typeof(ErrorMessageDto), 400)]
        [ProducesResponseType(typeof(ErrorMessageDto), 500)]
        public IActionResult Get([FromQuery(Name = "start")] DateTime? start,
            [FromQuery(Name = "end")] DateTime? end,
            [FromQuery(Name = "material_name")] string materialName,
            [FromQuery(Name = "material_type")] string materialType,
            [FromQuery(Name = "remark")] string remark,
            [FromQuery(Name = "usage_group_code")] string usageGroupCode,
            [FromQuery(Name = "ascending")] bool? ascending,
            [FromQuery(Name = "index")] int index = 1,
            [FromQuery(Name = "size")] int size = 10)
        {
            return this.Ok(this.materialConfigurationService.List(materialName, materialType, remark, usageGroupCode, start, end, ascending, index, size));
        }
        #endregion

        #region 获取素材信息
        /// <summary>
        /// 获取素材信息。
        /// </summary>
        /// <param name="materialConfigurationId">素材Id</param>
        /// <response code="200">素材信息</response>
        /// <response code="400">请求参数或输入的数据不正确。</response>
        /// <response code="500">服务器发生错误。</response>
        /// <response code="501">某些功能尚未实现。</response>
        /// <returns></returns>
        [HttpGet("{material_configuration_id}")]
        [ProducesResponseType(typeof(MaterialConfigurationDto), 200)]
        [ProducesResponseType(typeof(ErrorMessageDto), 400)]
        [ProducesResponseType(typeof(ErrorMessageDto), 500)]
        public IActionResult Get([FromRoute(Name = "material_configuration_id")] int materialConfigurationId)
        {
            return this.Ok(this.materialConfigurationService.Get(materialConfigurationId));
        }
        #endregion


        #region 创建素材信息
        /// <summary>
        /// 创建素材信息
        /// </summary>     
        /// <param name="materialConfigurationRequestDto">素材添加请求模型</param>
        /// <response code="200">VehicleDto</response>
        /// <response code="400">请求参数或输入的数据不正确。</response>
        /// <response code="500">服务器发生错误。</response>
        /// <response code="501">某些功能尚未实现。</response>
        /// <returns></returns>
        [HttpPost]
        [ProducesResponseType(typeof(MaterialConfigurationDto), 200)]
        [ProducesResponseType(typeof(ErrorMessageDto), 400)]
        [ProducesResponseType(typeof(ErrorMessageDto), 500)]
        public IActionResult Post([FromBody] MaterialConfigurationRequestDto materialConfigurationRequestDto)
        {
            return Ok(this.materialConfigurationService.Create(materialConfigurationRequestDto, this.Admin.FullName));
        }


        #endregion 创建素材信息

        #region 更新素材信息
        /// <summary>
        /// 更新素材信息。
        /// </summary>
        /// <param name="materialConfigurationId">素材Id</param>
        /// <param name="materialConfigurationSimPutDto">素材更改信息</param>
        /// <response code="200">成功更新用户信息</response>
        /// <response code="400">请求参数或输入的数据不正确。</response>
        /// <response code="500">服务器发生错误。</response>
        /// <response code="501">某些功能尚未实现。</response>
        /// <returns></returns>
        [HttpPut("{material_configuration_id}")]
        [ProducesResponseType(typeof(MaterialConfigurationDto), 200)]
        [ProducesResponseType(typeof(ErrorMessageDto), 400)]
        [ProducesResponseType(typeof(ErrorMessageDto), 500)]
        public IActionResult Put([FromRoute(Name = "material_configuration_id")] int materialConfigurationId, [FromBody] MaterialConfigurationSimPutDto materialConfigurationSimPutDto)
        {
            return Ok(this.materialConfigurationService.Update(materialConfigurationId, materialConfigurationSimPutDto, this.Admin.FullName));
        }
        #endregion 更新素材信息
    }
}
